package com.sprouting.ops.controller;

import cn.hutool.core.collection.CollUtil;
import com.sprouting.ops.model.ResultJson;
import com.sprouting.ops.model.vo.HomeBaseStatisticSingleVo;
import com.sprouting.ops.model.vo.HomeBaseStatisticVo;
import com.sprouting.ops.model.vo.VerificationCode;
import com.sprouting.ops.service.HomeService;
import com.sprouting.ops.utils.EntityTool;
import com.sprouting.ops.utils.IdTool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 首页
 *
 * @author ：LX（长沙麓谷）
 * @date 创建时间： 2025/10/11 00:16
 */
@Slf4j
@RestController
@RequestMapping("home")
public class HomeController {

    @Resource
    private HomeService homeService;

    /**
     * 获取首页统计- 基础统计
     * @return
     */
    @PostMapping("/getHomeBaseStatistic")
    public ResultJson getHomeBaseStatistic(){
        // 返回的是多个，现在要转换为一个
        List<HomeBaseStatisticVo> list = homeService.getHomeBaseStatistic();
        HomeBaseStatisticSingleVo vo = new HomeBaseStatisticSingleVo();
        if (CollUtil.isEmpty(list)){
            return ResultJson.success(vo);
        }

        Map<String, HomeBaseStatisticVo> map = EntityTool.toMap(list, HomeBaseStatisticVo::getTableName);
        vo.setApp(map.get("ops_app").getNum());
        vo.setComponent(map.get("ops_component").getNum());
        vo.setSite(map.get("ops_site").getNum());
        vo.setThirdParty(map.get("ops_third_party").getNum());
        vo.setPersonalPassword(map.get("ops_personal_password").getNum());
        vo.setKnowledgeComment(map.get("ops_knowledge_comment").getNum());
        vo.setUser(map.get("ops_user").getNum());
        return ResultJson.success(vo);
    }
}
